<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>聊天室</title>
    <link rel="shortcut icon" type="image/x-icon" href="dist/images/favicon.png">
    <link rel="stylesheet" href="dist/css/index.css">
</head>
<body>

<!-- 总页面 -->
<div id="app">
    <!-- 显示个人信息 + 在线信息列表 -->
    <div class="sidebar" :class="{close: !userListOpen}">
        <!-- 显示个人信息 -->
        <div class="card">
            <header>
                <img class="avatar" onclick="f.click()" title="点击设置头像" :src="url">
                <p class="name">{{sendName}}</p>
            </header>
            <footer>
                <input class="search" type="text" v-model.trim="searchVal" placeholder="搜索用户...">
            </footer>
        </div>
        <!-- 显示用户列表 -->
        <div class="list">
            <ul>
                <li @click="onAcquireName('群聊')" :class="{active: '群聊' == receiveName}">
                    <img src="dist/images/all.png" class="avatar" alt="">
                    <p class="name">群聊</p>
                </li>

                <li @click="onAcquireName('机器人')" :class="{active: '机器人' == receiveName}">
                    <img src="dist/images/robot.png" class="avatar" alt="">
                    <p class="name">机器人</p>
                </li>
                <li
                        v-for="user of searchList"
                        :class="{active: user.name == receiveName}"
                        @click="onAcquireName(user.name)"
                        v-if="user.name != sendName"
                        :key="user.name">
                    <img :src="user.url" class="avatar">
                    <p class="name">{{user.name}}</p>
                </li>
            </ul>
        </div>
    </div>
    <!-- 聊天页面 -->
    <div class="main" :class="{close: userListOpen}">
        <!-- 发送人 -->
        <div class="title">
            <span class="return" @click="() => {userListOpen = true, receiveName = ''}"><</span>
            {{receiveName}}
        </div>

        <!-- 聊天消息 -->
        <div class="container">
            <ul class="messages" id="scrollIV">
                <template v-for="item of message">
                    <p class="time" v-if="item.createDate">
                        <span>{{item.createDate}}</span>
                    </p>
                    <li :class="{ self: item.sendName == sendName}">
                        <div class="content">
                            <img class="avatar" :class="{mt: item.receiveName == '群聊'}" :src="item.url" @dblclick="() => { if (item.sendName != sendName) onAcquireName(item.sendName); }">
                            <div>
                                <p class="sendName" v-if="item.receiveName == '群聊' && item.sendName != sendName">
                                    {{item.sendName}}</p>
                                <div class="text" v-html="item.text"></div>
                            </div>
                        </div>
                    </li>
                </template>
            </ul>
        </div>

        <!-- 消息发送组件 -->
        <div class="text">
            <div
                    id="send"
                    contenteditable="true"
                    class="input"
                    @input="edit($event)"
                    @keyup.ctrl.enter="send()">
            </div>
            <button class="button" @click="send()">发送</button>
        </div>
    </div>
    <form method="post" action="/upload" name="upload" enctype="multipart/form-data" v-show="false">
        <input id="f" type="file" @change="chooseImg(this)" name="file"><br>
        <input type="hidden" name="sendName" v-model="sendName"><br>
    </form>
</div>

<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/store.js/1.3.20/store.js"></script>
<script src="dist/js/jquery.js"></script>
<script src="dist/js/jquery.cookie.js"></script>
<script src="dist/js/index.js"></script>
</body>
</html>
